package com.comtime.view;

import java.lang.reflect.Field;

import android.R;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.NumberPicker;
import android.widget.TextView;

public class MyNumPicker extends NumberPicker {
	
	public MyNumPicker(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}
	public MyNumPicker(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}
	public MyNumPicker(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	
	 @Override
	    public void addView(View child) {
	        super.addView(child);
	        updateView(child);
	    }
	 
	    @Override
	    public void addView(View child, int index,
	                        android.view.ViewGroup.LayoutParams params) {
	        super.addView(child, index, params);
	        updateView(child);
	    }
	 
	    @Override
	    public void addView(View child, android.view.ViewGroup.LayoutParams params) {
	        super.addView(child, params);
	        updateView(child);
	    }
	 
	    public void updateView(View view) {
	        if (view instanceof EditText) {
	            //这里修改字体的属性
	        	TextView textview=(TextView) view;
	        	textview.setTextColor(Color.WHITE);
	        	//设置分割线的颜色值
	        	setNumberPickerDividerColor(this);
	        }
	    }
	 
	    private void setNumberPickerDividerColor(NumberPicker numberPicker) {
	        NumberPicker picker = numberPicker;
	        Field[] pickerFields = NumberPicker.class.getDeclaredFields();
	        for (Field pf : pickerFields) {
	            if (pf.getName().equals("mSelectionDivider")) {
	                pf.setAccessible(true);
	                try {
	                    //设置分割线的颜色值
	                    pf.set(picker, new ColorDrawable(this.getResources().getColor(R.color.transparent)));
	                } catch (IllegalArgumentException e) {
	                    e.printStackTrace();
	                } catch (Resources.NotFoundException e) {
	                    e.printStackTrace();
	                } catch (IllegalAccessException e) {
	                    e.printStackTrace();
	                }
	                break;
	            }
	        }
	    }
	
}
